/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.utils;

/**
 *
 * @author  #0K Srinivasan <hashok.com>
 */
public class ColorMapper
{

    private int _alpha;
    private int _red;
    private int _green;
    private int _blue;
    private int _rgb;
    private int _argb;

    public ColorMapper(int r, int g, int b)
    {
        this(255, r, g, b);
    }

    public ColorMapper(float a, int r, int g, int b)
    {
        this((int) (a * 255.0f), r, g, b);
    }

    public ColorMapper(int a, int r, int g, int b)
    {
        _alpha = a;
        _red = r;
        _green = g;
        _blue = b;
        _combine();
    }

    public ColorMapper(int rgb)
    {
        this(255, rgb);
    }

    public ColorMapper(float a, int rgb)
    {
        this((int) (a * 255.0f), rgb);
    }

    public ColorMapper(int a, int rgb)
    {
        _alpha = a;
        _rgb = rgb;
        _extractRed();
        _extractGreen();
        _extractBlue();
    }
    
    private void _extractRed()
    {
        _red = (_rgb >> 16) & 0xFF;
    }
    
    private void _extractGreen()
    {        
        _green = (_rgb >> 8) & 0xFF;
    }
    
    private void _extractBlue()
    {
        _blue = (_rgb) & 0xFF;        
    }

    private void _combine()
    {
        _rgb = ((_red << 16) | (_green << 8) | (_blue));
        _argb = ((_alpha << 24) | (_red << 16) | (_green << 8) | (_blue));
    }

    public int getAlpha()
    {
        return _alpha;
    }

    public void setAlpha(int alpha)
    {
        this._alpha = alpha;
    }

    public int getRed()
    {
        return _red;
    }

    public void setRed(int red)
    {
        this._red = red;
    }

    public int getGreen()
    {
        return _green;
    }

    public void setGreen(int green)
    {
        this._green = green;
    }

    public int getBlue()
    {
        return _blue;
    }

    public void setBlue(int blue)
    {
        this._blue = blue;
    }

    public int getRGB()
    {
        return _rgb;
    }

    public void setRGB(int rgb)
    {
        this._rgb = rgb;
    }

    public int getARGB()
    {
        return _argb;
    }

    public void setARGB(int argb)
    {
        this._argb = argb;
    }
}
